import { DeleteDto, IndexDto, ShowDto } from '@libs/common/dto';
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { IsBoolean, IsNotEmpty, Min } from 'class-validator';
import { FindOperator } from 'typeorm';

import { DeviceCargoLane } from '../entities/device-cargo-lane.entity';

export class IndexDeviceCargoLaneDto extends IndexDto<DeviceCargoLane> {}

export class ShowDeviceCargoLaneDto extends ShowDto {}

export class UpdateDeviceCargoLaneDto {
  @ApiProperty()
  @IsNotEmpty({ message: 'id 不能为空' })
  id: string;

  @ApiProperty({ description: '商品ID' })
  productId: string;

  @ApiProperty({ description: '当前货道库存' })
  @IsNotEmpty({ message: '当前货道库存不能为空' })
  @Min(0, { message: '当前货道库存不能小于0' })
  store: number;
}

export class FindDeviceCargoLaneDto extends ShowDto {
  productId?: string;

  deviceRoad?: string;

  store?: number | FindOperator<number>;
}

export class StoreDeviceCargoLaneDto {
  @ApiProperty({ description: '商品ID' })
  @IsNotEmpty({ message: '商品ID不能为空' })
  productId: string;
}

/** 补货 */
export class ReplenishDeviceCargoLaneDto {
  @ApiProperty()
  @IsNotEmpty({ message: '货道ID不能为空' })
  id: string;

  @ApiProperty({ description: '补货数量' })
  @IsNotEmpty({ message: '补货数量不能为空' })
  @Min(0, { message: '补货数量不能小于0' })
  number?: number = 1;

  @ApiProperty({ description: '商品ID' })
  @IsNotEmpty({ message: '商品ID不能为空' })
  productId: string;
}

export interface DeviceCargoLaneProductVo {
  id: string;
  store: number;
  productName: string;
  productId: string;
  productImage: string;
  productDiscountPrice?: number;
  productOriginalPrice: number;
  productDescription?: string;
}

export interface OfflineDeviceCargoLaneDto {
  id: string;
}
